// pages/user/index.js
import { Token } from '../../utils/token.js';

import {My} from '../my/my-model.js';
var my=new My();







Page({

  /**
   * 页面的初始数据
   */
  data: {
    isuser:true,
    tel:'',
    usermoney:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    wx.setNavigationBarTitle({
      title: '我的钱包',
    })

    var appuser = wx.getStorageSync('userInfo');
    var params = {};
    my.UserInit((data) => {
  
              that.data.usermoney  = data.usermoney;
              that.setData({
                totalmoney:data.totalmoney
              });

              wx.hideNavigationBarLoading(); //完成停止加载
              wx.stopPullDownRefresh();
          },params);


      that.setData({
        userinfo:appuser
      });
  
  },

  toGetmoney:function(){

    var that = this;

    if(that.data.usermoney<=0)
    {
      
      wx.showModal({
        title: '提示',
        content: '余额不足,无法提现',
        showCancel: false
      })
      return


    }else{


      wx.showModal({
        title: '提示',
        content: '确认提现？',
        success: function (res) {
          if (res.confirm) {

            var params = {};

            my.getUserMoney((data) => {

              if(data.error == 0 )
              {
                wx.showModal({
                  title: '提示',
                  content: '提现成功',
                  showCancel: false,
                  success:function(){
                    wx.navigateTo({
                      url: "/pages/mymoneyrecord/index"
                    })

                  }
                })
            }else{

              wx.showModal({
                title: '提示',
                content: data.msg,
                showCancel: false
              })
              return

            }
              
      
                    
                },params);

          }}

        })





    }

  },

  


  toMymoneyrecord:function(){
    var that = this;
    wx.navigateTo({
      url: "/pages/mymoneyrecord/index"
    })

  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      var that = this;
      that.onLoad();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */ 
  onPullDownRefresh: function(){
    wx.showNavigationBarLoading();
    this.onLoad();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

    var that = this;
      return {
          title:'会员中心' ,
          path: '/pages/user/index'
      }

  }
})